import type { Categories } from '../type';

export const useCategories = defineStore(
  'categories',
  () => {
    const categories = ref<Categories[]>([]);
    const getCategories = async () => {
      if (categories.value.length <= 0) {
        const list = await get_categories();
        if (list) {
          categories.value = list;
          // console.log('getCategories', list);
        }
      }
      return categories;
    };
    return {
      categories,
      getCategories,
    };
  },
  { persist: true }
);
